<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增调课管理员设置')" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-adjustCourseAdmin-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">调课规则名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">年级：</label>
                <div class="col-sm-8">
                    <select name="gradeId" th:with="type=${@grade.getGradeList()}" required class="selectpicker">
                        <option value="">请选择</option>
                        <option th:each="grade : ${type}" th:text="${grade.gradeName}" th:value="${grade.id}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">调课管理员设置：</label>
                <div class="col-sm-8">
                    <select name = "adminIds" class="adminIds selectpicker" th:with="type=${@teacher.getTeacherList()}" required data-live-search="true" >
                        <option th:each="teacher : ${type}" th:text="${teacher.userName}" th:value="${teacher.userId}"></option>
                    </select>
                </div>
            </div>
           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">调课管理员设置(可多个)：</label>
                <input id="adminIds" name="adminIds" class="form-control" type="hidden" value="">
                <div class="col-sm-8">
                    <a class="btn btn-primary btn-sm" onclick="addUser()">&nbsp;添加审批人</a>
                    <ul class="sortable-list connectList agile-list">
                        <li class="warning-element" style="width:50%;">
                            <select class="adminIds" th:with="type=${@teacher.getTeacherList()}" required style="width:80%;">
                                <option th:each="teacher : ${type}" th:text="${teacher.userName}" th:value="${teacher.userId}"></option>
                            </select>
                            <div class="">
                                <a href="#" class="pull-right btn btn-xs btn-white" style="margin-top:-20px;" onclick="delUser(this)">移除</a>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
            <li class="warning-element" style="width:50%;display:none;" id="admin" >
                <select class="adminIds" th:with="type=${@teacher.getTeacherList()}" required style="width:80%;">
                    <option th:each="teacher : ${type}" th:text="${teacher.userName}" th:value="${teacher.userId}"></option>
                </select>
                <div class="">
                    <a href="#" class="pull-right btn btn-xs btn-white" style="margin-top:-20px;" onclick="delUser(this)">移除</a>
                </div>
            </li>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:src="@{/js/jquery-ui-1.10.4.min.js}"></script>
    <script type="text/javascript">
        $(document).ready(function () {
	        $(".sortable-list").sortable({connectWith: ".connectList"}).disableSelection()
	    });
        var prefix = ctx + "school/adjustCourseAdmin"
        $("#form-adjustCourseAdmin-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {

                $.operate.save(prefix + "/add", $('#form-adjustCourseAdmin-add').serialize());
            }
        }
        function addUser(){
            if($(".sortable-list .adminIds").length >= 3){
                $.modal.msgError('最多设置3个人管理员!');
                return ;
            }
            var opt = $("#admin").clone();
            $(opt).show();
            $(".sortable-list").append(opt);
        }
        function delUser(obj){
            $(obj).parents('li').remove();
        }
        function check(){
            var data = $(".sortable-list .adminIds");
            var adminIds = new Array(data.length)
            for(var i=0;i<data.length;i++){

                if(adminIds.indexOf(data[i].value) != -1){
                  $.modal.msgError('请勿重复设置管理员!');
                  return ;
                }
                 adminIds[i] = data[i].value;
            }
            $("#adminIds").val(adminIds.join(","));
        }

    </script>
</body>
</html>